<?php
/**
 * 退货订管理
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'includes/lib_goods.php');
@ini_set('display_errors',        2);
$act = !empty($_REQUEST['act'])?$_REQUEST['act']:'';

if ($act == 'add_order') {
            /*导入获取快递单号*/
            include_once('./includes/PHPExcel.php');
            $filename = $_FILES['file']['name'];
            $tmp_name = $_FILES['file']['tmp_name'];
            $objPHPExcel = PHPExcel_IOFactory::load($tmp_name);
            $indata = $objPHPExcel->getSheet(0)->toArray();
            // $area_id=$indata["1"]['6'];
            foreach ($indata as $key => $value) {
                if($key>0){
                        $order_sn[] = $value[0];
                }
            }
            $order_sn_list = implode( ',', $order_sn );
            /*查询订单信息*/
            $sql = " SELECT  order_id , order_sn , order_amount ,invoice_no FROM ".$GLOBALS['ecs']->table('order_info').
                   " WHERE  invoice_no IN ($order_sn_list) AND pay_id = 3 AND shipping_status != 2";
            $order = $GLOBALS['db']->getAll($sql);
            $smarty->assign('order',   $order);
}

if ($act == 'check_order') {
      $order_id = $_REQUEST['order_id'];
      $order_id_list = implode( ',', $order_id );
      /*修改订单*/
      $sql = "UPDATE " . $ecs->table('order_info') . " SET shipping_status = 2,pay_status =2,order_status = 5 ,confirm_time = ".time()." WHERE order_id IN ($order_id_list)";
      $GLOBALS['db']->query($sql);
      $links[] = array('href' => 'check.php', 'text' => "订单修改成功");
      sys_msg("订单修改成功", 100, $links);

}












/*批量导入进货价*/



if ($act == 'add_price') {
            /*导入获取快递单号*/
            include_once('./includes/PHPExcel.php');
            $filename = $_FILES['file']['name'];
            $tmp_name = $_FILES['file']['tmp_name'];
            $objPHPExcel = PHPExcel_IOFactory::load($tmp_name);
            $indata = $objPHPExcel->getSheet(0)->toArray();
            // $area_id=$indata["1"]['6'];
            foreach ($indata as $key => $value) {
                if($key>0&&!empty($value[1])){
                        $price_list[$key]['sku'] = $value[0];
                        $price_list[$key]['goods_xprice'] = round($value[1] ,2);
                }
            }
            /*跟新进货价*/
            foreach ($price_list as $key => $value) {
                    $sql = "UPDATE " . $ecs->table('goods_stock') . " SET goods_xprice = '".$value['goods_xprice']."' WHERE goods_sku =".$value['sku'];
                    $GLOBALS['db']->query($sql);
            }
}

if ($act == 'price') {
  $smarty->display("add_price.htm");   // 快递类型
}else{
  $smarty->display("check.htm");   // 快递类型
}



?>